// pages/class/class.js
const config = getApp().globalData.config
const app = getApp()
Page({
  data: {
    item: [],
    auth: {},
    goodsId: '',
    listInfo: [
      {
        title: '客服',
        imgUrl: '/image/class.png',
        curUrl: '/image/class.png',
        bindtap: 'open-type=\'contact\'',
      },
      {
        title: '加入购物车',
        imgUrl: '/image/class.png',
        curUrl: '/image/class.png',
        bindtap: 'bindtap =\'shoppingCart\'',
      },
      {
        title: '立即购买',
        imgUrl: '/image/class.png',
        curUrl: '/image/class.png',
        bindtap: 'bindtap ="buy"',
      },
    ],
  },
  member: function (e) {
    //开通会员---预留
    this.setData({
      curIdx: e.currentTarget.dataset.current
    })
    wx.navigateTo({
      url: `/pages/goodsDetail/goodsDetail?goodsId=${id}`,
    })  
  },
  assure: function (e) {
    //正品保障
      
    wx.navigateTo({
      url: `/pages/assureNews/assureNews?key=assure`,
    })  
     
  },
  newsPeople: function (e) {
    //新人购买指南
    // this.setData({
    //   curIdx: e.currentTarget.dataset.current
    // })
    wx.navigateTo({
      url: `/pages/assureNews/assureNews?key=newPeople`,
    })  
    // console.log(this.data.listInfo)
    //  console.log(this.data.curIdx) 
  },
  machine: function (e) {
    //售卖机购买
    this.setData({
      curIdx: e.currentTarget.dataset.current
    })
    wx.navigateTo({
      url: `/pages/goodsDetail/goodsDetail?goodsId=${id}`,
    })  
    console.log(this.data.listInfo)
    //  console.log(this.data.curIdx) 
  },
  shoppingCart: function (e) {
    //购物车
    var id = e.currentTarget.dataset.id;
    wx.switchTab({
      url: '/pages/shopcar/shopcar?goodsId=' + id,
    })

    //  console.log(this.data.curIdx) 
  },
  shopCart: function (e) {
    //加入购物车
    var id = e.currentTarget.dataset.id;
    

    //  console.log(this.data.curIdx) 
  },
  buy: function (e) {
    //购买
    this.setData({
      curIdx: e.currentTarget.dataset.current
    })
    wx.navigateTo({
      url: `/pages/goodsDetail/goodsDetail?goodsId=${id}`,
    })  
    console.log(this.data.listInfo)
    //  console.log(this.data.curIdx) 
  },
 
  onLoad(query) {
    if (query && query.goodsId) {
      let goodsId = query && query.goodsId
       
      this.getGoodsId(goodsId)
    }
  },
  getGoodsId(goodsId) {
    const openid = this.data.openid
    wx.request({
      url: config.urlBase + 'getGoodsDetail', 
      data: {
        uid: openid,
        goodsId:goodsId, 
      },
      success: (res) => {
        let data = res.data
        if (data.code === '10000') {
          let item = data.data || {}
          // if (!utils.isEmptyObject(item)) {
            this.setData({
              item,
            })
          wx.setNavigationBarTitle({
            title: item.title
          })
          console.log(item);
          // }
        } else {
          wx.showToast({
            title: data.msg.toString(),
            icon: 'none',
          })
        }
      },
      fail: () => {
        wx.showToast({
          title: '网路开小差，请稍后再试',
          icon: 'none',
        })
      },
    })
  },
})